<?php

namespace app\index\controller;

use think\Controller;
use think\Session;

class Trade extends Ubase
{
	public function index ()
	{
		$user = [];
        $no_title = db('notice')->order('create_time desc')->where('n_keywords',0)->field('n_title')->limit(3)->select();
        $this->assign('notice',$no_title);
        if (Session::has('aid')) {
            $user = db('ns_user')->where('id',Session::get('aid'))->find();
        }
        $this->assign('user',$user);
		return $this->fetch();
	}

	public function lists ()
	{
		$group = db('tr_group') -> select();
		$data = [];
		$times = db('trade')->distinct(true)->order('time')->field('time')->select();
		$where = [];
		foreach ($group as $v) {
			$info = [];
			$where['cid'] = $v['id'];
			foreach($times as $tm) {
				$where['time'] = $tm['time'];
				$val = db('trade')->where($where)->find();
				if($val)
				{
					$info[$tm['time']] = $val['val'];
				}else{
					$info[$tm['time']] = '';
				}
			}
			array_push($data, $info);
		}
		$arr = [];
		foreach ($times as $tm) {
			array_push($arr,$tm['time']);
		}
		$msg = [];
		$msg['data'] = $data;
		$msg['times'] = $arr;
		$msg['group'] = $group;
		return $msg;
	}
}